Skip to content

Fix filter chains with different filter regions - #1144

Merged
LaurenzV merged 1 commit into
linebender:mainfrom
teolines:fix-lighting-region-mismatch
Oct 7, 2026
Merged

LaurenzV merged 1 commit into
linebender:mainfrom
teolines:fix-lighting-region-mismatch

Conversation

@teolines

Copy link
Copy Markdown
Contributor

Tiny elements with a lighting filter crashed because rounding made the filter area 1px smaller than the input. The output now matches the input size.

Fixes #1141

LLM Contributions: investigation, implementation and tests with Claude Code, reviewed by me. The description is my own, edited for grammar.

@LaurenzV

LaurenzV commented Oct 7, 2026

Copy link
Copy Markdown
Collaborator

Hmm, I will have to check, but I suspect this is just a band-aid fix and doesn't fix a (possibly) more fundamental issue in the current code.

Filter inputs could retain the full layer dimensions while outputs used the smaller filter region, causing out-of-bounds writes. Crop the source to the working region, adjust its coordinate origin, and place the result back at the original offset. This also preserves clipping for chained filters with different regions.

Fixes linebender#1141.
@LaurenzV
LaurenzV force-pushed the fix-lighting-region-mismatch branch from 0020241 to 5bcece6 Compare October 7, 2026 19:10
@LaurenzV

LaurenzV commented Oct 7, 2026

Copy link
Copy Markdown
Collaborator

Okay honestly, I'm also not 100% confident here, it's very hard to wrap my head around the filter code. But I believe there was a more general issue: Each filter assumes that the input and output region are the same, but that doesn't have to be the case if two filter's in a chain cover different regions. I've added some code to first crop it in case they don't match, which fixes your issue and another issue I've found. Not super efficient, but we only pay the cost in that specific situation, the normal case remains unchanged, so hopefully good enough.

Thanks!

@LaurenzV LaurenzV changed the title Fix a panic in lighting filters on a region smaller than the input Fix filter chais with different filter regions Oct 7, 2026
@LaurenzV LaurenzV changed the title Fix filter chais with different filter regions Fix filter chains with different filter regions Oct 7, 2026
@LaurenzV
LaurenzV merged commit ff43ecf into linebender:main Oct 7, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Panic when rendering lighting filters: index out of bounds

2 participants